# write by hashaki
# first edit on 2018/11/25
# last change on 2018/11/26
# machine learning for similer
import tensorflow as tf
import numpy as np

class SimilerByTensorflow:
    def __init__(self):
        self.iteration=1000
        self.learning_rate=0.01
    
    def analyzerPriceItSelf_LinearRegretion(self,data1,data2):
        '''价格数据自分析'''
        samples=data1.shape[0]             # 样本数

        x=tf.placeholder("float")
        y=tf.placeholder("float")

        w=tf.Variable(0.0,name='weight')
        b=tf.Variable(0.0,name='bais')

        pred=tf.add(tf.multiply(x,w),b)
        cost=tf.reduce_sum(tf.pow(pred-y,2))/(2*samples)

        optimizer=tf.train.GradientDescentOptimizer(self.learning_rate).minimize(cost)
        init=tf.global_variables_initializer()
        
        with tf.Session() as sess:
            sess.run(init)
            for i in range(self.iteration):
                for (X,Y) in zip(data1,data2):
                    sess.run(optimizer,feed_dict={x:X,y:Y})

                c=sess.run(cost,feed_dict={x:data1,y:data2})
                print('集数：','%04d'%(i+1),'代价函数：','{:.9f}'.format(c),'权重=',sess.run(w),'偏差=',sess.run(b))
            
            training_cost=sess.run(cost,feed_dict={x:data1,y:data2})
        
    def analyzerPriceItSelf_LogisticRegretion(self,data1,data2):
        '''逻辑分析价量关系'''
        pass
    
    def analyzerPriceItSelf_NearestNeighbor(self,data1,data2):
        '''最近邻拟合价量关系'''
        pass
    
    def analyzerPriceItSelf_KMeans(self,data1,data2):
        '''K-means算法'''
        pass
    
    def analyzerPriceItSelf_RandomForest(self,data1,data2):
        '''随即森林'''
        pass
    
    def analyzerPriceItSelf_GradientBoostedDecisionTree(self,data1,data2):
        '''GBDT'''
        pass

    def analyzerPriceItSelf_NeuralNetworks(self,data1,data2):
        '''神经网络'''
        x=tf.placeholder("float")
        y=tf.placeholder("float")

        distance=tf.reduce_sum(tf.abs(tf.add(x,tf.negative(x))),reduction_indices=1)

        pred=tf.arg_min(distance,0)

        accuracy=0

        init=tf.global_variables_initializer()


    